﻿using Autofac;
using Autofac.Integration.Mvc;
using Software41.Tracking.Data;
using Software41.Tracking.Data.EF;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;

namespace Software41.Tracking.Web.Infrastructure
{
    public class Bootstrapper
    {

        public void Initialize()
        {
            //TODO: Move this into its own Config
            var builder = new ContainerBuilder();
            builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();

            builder.RegisterType<BAMRepository>().As<IBAMRepository>()
                            .WithParameter("bamServerName", ConfigurationManager.AppSettings["BAMServerName"]);

            builder.RegisterType<ProcessTraceInfoRepository>().As<IProcessTraceInfoRepository>();
            builder.RegisterType<ProcessTraceInfoContext>();

            //this registers the Http abstractions (e.g. - HttpContextBase, etc) http://code.google.com/p/autofac/wiki/Mvc3Integration
            builder.RegisterModule(new AutofacWebTypesModule());



            IContainer container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }

    }
}